package com.mikufufu.blog.listener;

import com.mikufufu.blog.model.event.LogEvent;
import com.mikufufu.blog.service.OperateLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class LogEvenListener {

    @Autowired
    private OperateLogService operateLogService;

    @Async("logTaskExecutor")  // 指定线程池
    @EventListener
    public void onApplicationEvent(LogEvent event) {
        operateLogService.save(event.getOperateLog());
    }
}
